import 'package:flutter_app/base/base_presenter.dart';
import 'package:flutter_app/base/i_view.dart';
import 'package:flutter_app/constant.dart';
import 'package:flutter_app/http/http_manager.dart';
import 'package:flutter_app/model/article_resp.dart';
import 'package:oktoast/oktoast.dart';

class ArticleListPresenter extends BasePresenter<IArticleListView> {
  ArticleListPresenter(IArticleListView view) : super(view);

  void requestArticles(String id, int pageNum) {
    String url =
        Constant.API_ARTICLE_LIST + id + '/' + pageNum.toString() + '/json';
    HttpManager().get(
        url: url,
        tag: url,
        successCallback: (data) {
          var articleGroup = ArticleGroup.fromJson(data);
          view.callBackArticles(articleGroup.datas);
        },
        errorCallback: (data) {
          showToast(data.message);
        });
  }
}

abstract class IArticleListView extends IView {
  ///回调文章列表
  void callBackArticles(List<ArticleBean> list);
}
